namespace ScrumSprintMonitor.Implementation
{
	#region #using Directives

	using System;
	using System.Collections.Generic;
	using System.ComponentModel.Composition;
	using System.Linq;

	using Infrastructure;

	#endregion

	public class AvatarProviderStore : IAvatarProviderStore
	{
		private readonly IList<IAvatarProvider> avatarProvidersList = new List<IAvatarProvider>();

		[ImportMany(typeof(IAvatarProvider))]
		public IList<IAvatarProvider> Providers
		{
			get { return this.avatarProvidersList; }
		}

		#region Implementation of IAvatarProviderStore

		public IAvatarProvider GetProvider(string providerId)
		{
			return this.avatarProvidersList.FirstOrDefault(x => x.ProviderId == providerId);
		}

		public void RegisterProvider(string providerId, IAvatarProvider provider)
		{
			if (this.avatarProvidersList.Any(x => x.ProviderId == providerId))
			{
				throw new ArgumentException("providerId is already registered.", "providerId");
			}

			this.avatarProvidersList.Add(provider);
		}

		#endregion
	}
}